/**
 * 
 */
package array.passed;

/**
 * @author xyyi
 *
 */
public class RotateImage {

	/**
	You are given an n x n 2D matrix representing an image.

	Rotate the image by 90 degrees (clockwise).

	Follow up:
	Could you do this in-place?
	 */
	public void rotate(int[][] matrix) {
		// Start typing your Java solution below
		// DO NOT write main() function
		int n = matrix.length;
		for (int level = 0, size = n / 2; level < size; level++) {
			for (int i = level; i < n - level - 1; i++) {
				int temp = matrix[level][i];
				matrix[level][i] = matrix[n - i - 1][level];
				matrix[n - i - 1][level] = matrix[n - level - 1][n - i - 1];
				matrix[n - level - 1][n - i - 1] = matrix[i][n - level - 1];
				matrix[i][n - level - 1] = temp;
			}
		}
	}

	/**
	 * 
	 */
	public RotateImage() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
